package com.zhuss.food.food;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.zhuss.bean.bo.food.food.CreateFoodBo;
import com.zhuss.bean.bo.food.food.DeleteFoodBo;
import com.zhuss.bean.bo.food.food.StartFoodBo;
import com.zhuss.bean.bo.food.food.StopFoodBo;
import com.zhuss.bean.bo.food.food.UpdateFoodBo;
import com.zhuss.common.OperateService;
import com.zhuss.common.Processor;
import com.zhuss.exception.WpsException;

/**
 * 餐品操作service（基本操作）
 * @author zhushanshuo
 * @Date 2020/02/28 16:01
 *
 */
@Component("foodOperateService")
public class FoodOperateService implements OperateService<Void, Object> {
	
	@Autowired
	@Qualifier("foodCreate")
	private Processor<Object, CreateFoodBo> foodCreate;
	
	@Autowired
	@Qualifier("foodUpdate")
	private Processor<Object, UpdateFoodBo> foodUpdate;
	
	@Autowired
	@Qualifier("foodStart")
	private Processor<Object, StartFoodBo> foodStart;
	
	@Autowired
	@Qualifier("foodStop")
	private Processor<Object, StopFoodBo> foodStop;
	
	@Autowired
	@Qualifier("foodDelete")
	private Processor<Object, DeleteFoodBo> foodDelete;
	
	/**
	 * 创建
	 */
	@Override
    @Transactional(rollbackFor = Exception.class)
	public Void create(Object param) throws WpsException {
		
		CreateFoodBo bo = (CreateFoodBo) param;
		
		foodCreate.process(bo);
		
		return null;
	}
    
	/**
	 * 修改
	 */
	@Override
    @Transactional(rollbackFor = Exception.class)
    public Void update(Object param) throws WpsException {
    	
		UpdateFoodBo bo = (UpdateFoodBo) param;
		
		foodUpdate.process(bo);
		
    	return null;
    }
	
	/**
	 * 删除
	 */
	@Override
	@Transactional(rollbackFor = Exception.class)
	public Void delete(Object param) throws WpsException {
		
		DeleteFoodBo bo = (DeleteFoodBo) param;
		
		foodDelete.process(bo);
		
		return null;
	}
	
	/**
	 * 启用餐品
	 */
	@Transactional(rollbackFor = Exception.class)
	protected Void start(Object param) throws WpsException {
		
		StartFoodBo bo = (StartFoodBo) param;
		
		foodStart.process(bo);
		
		return null;
	}
	
	/**
	 * 停用餐品
	 */
	@Transactional(rollbackFor = Exception.class)
	protected Void stop(Object param) throws WpsException {
		
		StopFoodBo bo = (StopFoodBo) param;
		
		foodStop.process(bo);
		
		return null;
	}
	
}

